home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 013 / nmove586.arc / PROCED.ASM < prev   
Encoding:
Assembly Source File  |  1986-01-01  |  6.6 KB  |  360 lines

  1.     TITLE PROCED
  2.  
  3.  
  4.  
  5. ;Routines
  6.  
  7.     public    FIXUP_COMMAND_LINE,GET_LINE_LENGTH,GLOOP,TABS2SPACES,TABLOOP
  8.     public    TABS_DONE,UPPER_CASE,LCLOOP,LSKIP,GET_D_SWITCH,D_NOT_FOUND
  9.     public    MOVE_PARAMETERS,MOVE_FIRST,MOVE_SECOND,ONLY_ONE,PAR_ERROR
  10.     public    PRINT_FILENAME,PRINT_CRLF,MOVE_PNAME,LOOK_FOR_COLON,P1,MOVE_P
  11.     public    TO_BIG_ERROR,APPEND_STAR_DOT_STAR,APPEND_ERROR,SKIP_SPACES
  12.  
  13. ;Variables
  14.  
  15.     public    CRLF,STAR_DOT_STAR
  16.  
  17. G    GROUP    CODE
  18. CODE    SEGMENT    PUBLIC
  19.     ASSUME    CS:G, DS:G, ES:G, SS:G
  20.  
  21. SPACE        EQU    20H
  22. NULL        EQU    0
  23. MAX_NAME_LENGTH    EQU    80
  24. CR        EQU    0DH
  25. LF        EQU    0AH
  26. TAB        EQU    9
  27. DISPLAY_CHAR    EQU    2
  28. DISPLAY_STRING    EQU    9
  29.  
  30. CRLF        DB    CR, LF, "$"
  31. STAR_DOT_STAR    DB    "\*.*", NULL
  32.  
  33. ;--------------------------------------------------------------------
  34.  
  35. FIXUP_COMMAND_LINE    PROC
  36. ; This routine changes all the tabs on the command line to single spaces,
  37. ; and changes all lower case to upper case.
  38. ; call: es:80h -> command line
  39. ; return: cx = number of characters on the command line including the cr.
  40.  
  41.     MOV    SI, 81H
  42.     CALL     GET_LINE_LENGTH
  43.     CALL     TABS2SPACES
  44.     CALL     UPPER_CASE
  45.     RET
  46. FIXUP_COMMAND_LINE    ENDP
  47.  
  48. ;--------------------------------------------------------------------
  49.  
  50. GET_LINE_LENGTH    PROC
  51. ; Get the length of this line and change the cr to a space.
  52. ; call: es:si -> the start of the line ending with a cr.
  53. ; return: cx = number characters on the line counting the cr.
  54.  
  55.     CLD
  56.     MOV DI, SI
  57.     MOV AL, CR
  58.     XOR CX, CX
  59. GLOOP:
  60.     INC CX
  61.     SCASB
  62.     JNZ GLOOP
  63.     
  64.     MOV    [DI-1], BYTE PTR SPACE        ; change the cr to a space
  65.     RET
  66. GET_LINE_LENGTH    ENDP
  67.  
  68. ;--------------------------------------------------------------------
  69.  
  70. TABS2SPACES    PROC
  71. ; Change all tabs to spaces on the line.
  72. ; call: es:si -> the start of the line 
  73. ;    cx = number characters on the line
  74. ;     cld (up direction)
  75. ;    ds = es
  76.  
  77.     PUSH CX
  78.  
  79.     MOV DI, SI
  80.     MOV AL, TAB
  81.     
  82. TABLOOP:
  83.     REPNZ SCASB
  84.     JNZ TABS_DONE
  85.     
  86.     MOV [DI-1], BYTE PTR SPACE
  87.     JCXZ TABS_DONE
  88.     JMP TABLOOP
  89.     
  90. TABS_DONE:
  91.     POP CX
  92.     RET
  93. TABS2SPACES    ENDP
  94.  
  95. ;--------------------------------------------------------------------
  96.  
  97. UPPER_CASE    PROC
  98. ; Convert all lower case to upper case on this line.
  99. ; call: es:si -> the start of the line
  100. ;    cx = the number of characters on the line
  101. ;    ds = es
  102.  
  103.     PUSH CX
  104.     PUSH SI
  105.  
  106.     MOV DI, SI
  107.  
  108. LCLOOP:
  109.     LODSB
  110.  
  111.     CMP AL, "a"
  112.     JB LSKIP
  113.     CMP AL, "z"
  114.     JA LSKIP
  115.  
  116.      AND AL, 11011111B
  117.  
  118. LSKIP:
  119.     STOSB
  120.     LOOP LCLOOP
  121.  
  122.     POP SI
  123.     POP CX
  124.     RET    
  125. UPPER_CASE    ENDP
  126.  
  127. ;--------------------------------------------------------------------
  128.  
  129. GET_D_SWITCH    PROC
  130. ; This routine looks for "/D " switch on the command line.
  131. ; Its assumed that the command line has been "fixed up".
  132. ; After it has found the switch it changes it to spaces.
  133. ; call: si -> command line
  134. ;    cx = number of character on the command line including the cr
  135. ; return: al = 0 if no "d" switch
  136. ;      al = 1 if the "d" switch was found
  137.     PUSH    CX
  138.  
  139.     MOV    DI, SI
  140.     MOV    AL, '/'
  141.     REPNZ    SCASB
  142.     JNZ    D_NOT_FOUND
  143.  
  144.     MOV    [DI-1], BYTE PTR SPACE
  145.  
  146.     CALL    SKIP_SPACES
  147.  
  148.     MOV    AL, 'D'
  149.     SCASB
  150.     JNZ    D_NOT_FOUND
  151.  
  152.     MOV    AL, SPACE
  153.     SCASB    
  154.     JNZ    D_NOT_FOUND
  155.  
  156.     MOV    [DI-2], BYTE PTR SPACE
  157.     MOV    AL, 1
  158.     POP    CX
  159.     RET
  160.  
  161. D_NOT_FOUND:
  162.     XOR    AL, AL
  163.     POP    CX
  164.     RET
  165. GET_D_SWITCH    ENDP
  166.  
  167. ;--------------------------------------------------------------------
  168.  
  169. MOVE_PARAMETERS        PROC
  170. ; Move the two filenames from the command line to two buffers. End the
  171. ; two filenames with a null.
  172. ; Assume that the switch has been changed to spaces and the cr has been 
  173. ; replaced with a space.
  174. ; call: dx -> location to put the first filename
  175. ;    bx -> location to put the second filename
  176. ;    81h -> command line
  177. ;    cx = line length
  178. ; return: carry = 1 if and error ocurred and al = error code
  179. ;      if error, al = 7 - "no parameters"
  180.     
  181.     MOV    DI, 81H
  182.     CALL     SKIP_SPACES
  183.     CMP    CX, 1
  184.     JZ    PAR_ERROR
  185.  
  186.     MOV    SI, DI
  187.     MOV    DI, DX
  188.  
  189. MOVE_FIRST:
  190.     MOVSB
  191.     CMP    [SI], BYTE PTR SPACE
  192.     LOOPNZ    MOVE_FIRST
  193.  
  194.     MOV    AL, NULL        ; end each name with a null
  195.     STOSB            
  196.     
  197.     MOV    DI, SI
  198.  
  199.     CALL    SKIP_SPACES
  200.     CMP    CX, 1
  201.     JZ    ONLY_ONE
  202.  
  203.     MOV    SI, DI
  204.     MOV    DI, BX
  205.  
  206. MOVE_SECOND:
  207.     MOVSB
  208.     CMP    [SI], BYTE PTR SPACE
  209.     LOOPNZ    MOVE_SECOND
  210.  
  211.     MOV    AL, NULL
  212.     STOSB
  213.  
  214.     CLC
  215.     RET
  216.  
  217. ONLY_ONE:
  218.     MOV    CX, 20            ; store 20 null for the second name
  219.     MOV    AL, NULL
  220.     REP    STOSB
  221.     CLC
  222.     RET
  223.  
  224. PAR_ERROR:
  225.     STC
  226.     MOV    AL, 7
  227.     RET
  228. MOVE_PARAMETERS    ENDP
  229.  
  230. ;--------------------------------------------------------------------
  231.  
  232. PRINT_FILENAME        PROC
  233. ; Print an ascii string then print a cr, lf.
  234. ; call: si -> first character of the ascii string to be printed ending with a
  235. ;    null
  236.     
  237.     LODSB
  238.     CMP    AL, NULL
  239.     JZ    PRINT_CRLF
  240.     
  241.     MOV    DL, AL
  242.     MOV    AH, DISPLAY_CHAR
  243.     INT    21H
  244.  
  245.     JMP    PRINT_FILENAME
  246.  
  247. PRINT_CRLF:
  248.     MOV    AH, DISPLAY_STRING
  249.     LEA    DX, CRLF
  250.     INT    21H
  251.  
  252.     RET
  253. PRINT_FILENAME    ENDP
  254.  
  255. ;--------------------------------------------------------------------
  256.  
  257. MOVE_PNAME    PROC
  258. ; This procedure will move a "pname" to the last position of another name.
  259. ; The last position is either:
  260. ; 1. after the last "\"
  261. ; 2. after the ":" 
  262. ; 3. at the first location.
  263. ; call: si -> pname to move
  264. ;    di -> start of a name ending with a null.
  265. ;    cld (up direction)
  266. ; return: carry = 1 if the name was to big and al = error code of 15
  267.  
  268.     MOV    BX, DI
  269.         
  270.     MOV     CX,MAX_NAME_LENGTH    ; Go to the end of the name
  271.     MOV     AL,NULL
  272.     REPNZ     SCASB
  273.     JNZ    TO_BIG_ERROR
  274.  
  275.     DEC    DI
  276.     DEC     DI            ; calculate the size of the name
  277.     MOV    AX, MAX_NAME_LENGTH
  278.     SUB    AX, CX
  279.     MOV    CX, AX
  280.  
  281.     STD                ; look for a "\"
  282.     MOV    AL, "\"
  283.     REPNZ    SCASB
  284.     JZ    P1
  285.  
  286. LOOK_FOR_COLON:
  287.     MOV    DI, BX
  288.     CMP    [DI+1], BYTE PTR ":"
  289.     JNZ    MOVE_P
  290.  
  291. P1:
  292.     INC    DI
  293.     INC    DI
  294.     
  295. MOVE_P:
  296.     CLD
  297.     MOV    CX, 13
  298.     REP    MOVSB
  299.     MOV    AL, NULL
  300.     STOSB
  301.     CLC
  302.     RET
  303.  
  304. TO_BIG_ERROR:
  305.     MOV    AL, 15
  306.     STC
  307.     RET
  308. MOVE_PNAME    ENDP
  309.         
  310. ;--------------------------------------------------------------------
  311.  
  312. APPEND_STAR_DOT_STAR    PROC
  313. ; Append "\*.*" to the end of a name 
  314. ; call: ds:si -> the beginning of a name ending with a null.
  315. ;    es = ds
  316. ;    cld (up direction)
  317. ; return: carry = 1 if the name excedes the max. name length and al =
  318. ;      error code of 15
  319.  
  320.     MOV    CX, MAX_NAME_LENGTH
  321.     MOV    DI, SI
  322.     MOV    AL, NULL
  323.     REPNZ    SCASB
  324.     JCXZ    APPEND_ERROR
  325.  
  326.     DEC    DI
  327.     LEA    SI, STAR_DOT_STAR
  328.     MOV    CX, 5
  329.     REP    MOVSB
  330.  
  331.     CLC
  332.     RET
  333.  
  334. APPEND_ERROR:
  335.     MOV    AL, 15
  336.     STC
  337.     RET
  338. APPEND_STAR_DOT_STAR    ENDP
  339.  
  340. ;--------------------------------------------------------------------
  341.  
  342. SKIP_SPACES    PROC
  343. ; call: es:di -> at a string
  344. ;    cx = max. number of characters to skip
  345. ; return: es:di -> first non space character
  346.  
  347.     MOV     AL, SPACE
  348.  
  349.     REPZ     SCASB
  350.  
  351.     INC    CX
  352.     DEC     DI
  353.     RET
  354. SKIP_SPACES    ENDP
  355.  
  356. ;--------------------------------------------------------------------
  357.  
  358. CODE        ENDS
  359.         END
  360.